function formatPrefix(csskey = 'transform') {
	const el = document.createElement('div');
	const reg = /^(Moz|(w|W)ebkit|O|ms)(?=[A-Z])/;
	let vendor =
		(() => {
			for (const p in el.style) if (reg.test(p)) return p.match(reg)[0];
		})() || '';
	vendor += csskey.charAt(0).toUpperCase() + csskey.slice(1);
	return vendor;
}

function getPrefix() {
	// e.g: get '-webkit-' from window
	const el = document.createElement('div');
	const reg = /^(Moz|(w|W)ebkit|O|ms)(?=[A-Z])/;
	const vendor =
		(() => {
			for (const p in el.style) if (reg.test(p)) return p.match(reg)[0];
		})() || '';
	return `-${vendor.toLowerCase()}-`;
}

function setPrefix(pfx, csskey) {
	for (const key in csskey) {
		csskey[pfx + key] = csskey[key];
	}
	return csskey;
}

function injectDomToBody(domString) {
	const domBody = document.body.innerHTML;
	document.body.innerHTML = domString + domBody;
}

function injectStyleToHead(cssStr) {
	const style = document.createElement('style');
	style.innerHTML = cssStr;
	document.getElementsByTagName('head')[0].appendChild(style);

	// if(this.styleTag) this.styleTag.remove();
	// this.styleTag = document.createElement('style');
	// this.styleTag.innerHTML = `
	// `;
	// document.head.appendChild( this.styleTag );
}

function getScrollingElement() {
	if ('scrollingElement' in document) {
		return document.scrollingElement;
	}
	if (navigator.userAgent.includes('WebKit')) {
		return document.body;
	}
	return document.documentElement;
}

function getEaseStyle(type) {
	let t = 'ease-in-out';
	if (type == 'easeInQuad' || type == 'ease-in-quad') t = 'cubic-bezier(0.550, 0.085, 0.680, 0.530)';
	if (type == 'easeOutQuad' || type == 'ease-out-quad') t = 'cubic-bezier(0.250, 0.460, 0.450, 0.940)';
	if (type == 'easeInOutQuad' || type == 'ease-in-out-quad') t = 'cubic-bezier(0.455, 0.030, 0.515, 0.955)';

	if (type == 'easeInCubic' || type == 'ease-in-cubic') t = 'cubic-bezier(0.550, 0.055, 0.675, 0.190)';
	if (type == 'easeOutCubic' || type == 'ease-out-cubic') t = 'cubic-bezier(0.215, 0.610, 0.355, 1.000)';
	if (type == 'easeInOutCubic' || type == 'ease-in-out-cubic') t = 'cubic-bezier(0.645, 0.045, 0.355, 1.000)';

	if (type == 'easeInQuart' || type == 'ease-in-quart') t = 'cubic-bezier(0.895, 0.030, 0.685, 0.220)';
	if (type == 'easeOutQuart' || type == 'ease-out-quart') t = 'cubic-bezier(0.165, 0.840, 0.440, 1.000)';
	if (type == 'easeInOutQuart' || type == 'ease-in-out-quart') t = 'cubic-bezier(0.770, 0.000, 0.175, 1.000)';

	if (type == 'easeInQuint' || type == 'ease-in-quint') t = 'cubic-bezier(0.755, 0.050, 0.855, 0.060)';
	if (type == 'easeOutQuint' || type == 'ease-out-quint') t = 'cubic-bezier(0.230, 1.000, 0.320, 1.000)';
	if (type == 'easeInOutQuint' || type == 'ease-in-out-quint') t = 'cubic-bezier(0.860, 0.000, 0.070, 1.000)';

	if (type == 'easeInSine' || type == 'ease-in-sine') t = 'cubic-bezier(0.470, 0.000, 0.745, 0.715)';
	if (type == 'easeOutSine' || type == 'ease-out-sine') t = 'cubic-bezier(0.390, 0.575, 0.565, 1.000)';
	if (type == 'easeInOutSine' || type == 'ease-in-out-sine') t = 'cubic-bezier(0.445, 0.050, 0.550, 0.950)';

	if (type == 'easeInCirc' || type == 'ease-in-circ') t = 'cubic-bezier(0.600, 0.040, 0.980, 0.335)';
	if (type == 'easeOutCirc' || type == 'ease-out-circ') t = 'cubic-bezier(0.075, 0.820, 0.165, 1.000)';
	if (type == 'easeInOutCirc' || type == 'ease-in-out-circ') t = 'cubic-bezier(0.785, 0.135, 0.150, 0.860)';

	if (type == 'easeInBack' || type == 'ease-in-back') t = 'cubic-bezier(0.600, -0.280, 0.735, 0.045)';
	if (type == 'easeOutBack' || type == 'ease-out-back') t = 'cubic-bezier(0.175, 0.885, 0.320, 1.275)';
	if (type == 'easeInOutBack' || type == 'ease-in-out-back') t = 'cubic-bezier(0.680, -0.550, 0.265, 1.550)';

	if (type == 'easeInExpo' || type == 'ease-in-expo') t = 'cubic-bezier(0.950, 0.050, 0.795, 0.035)';
	if (type == 'easeOutExpo' || type == 'ease-out-expo') t = 'cubic-bezier(0.190, 1.000, 0.220, 1.000)';
	if (type == 'easeInOutExpo' || type == 'ease-in-out-expo') t = 'cubic-bezier(1.000, 0.000, 0.000, 1.000)';
	return t;
}

export { formatPrefix, getPrefix, setPrefix, injectDomToBody, injectStyleToHead, getScrollingElement, getEaseStyle };
